﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using outREACH.App_Code;

namespace outREACH
{
    public partial class EducationForumviewaspx : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null)
            {
                if (Session["UserName"] != null)
                {
                    Label lbl1 = (Label)Master.FindControl("Label1");
                    lbl1.Text = "Welcome " + Session["Username"].ToString() + "!";
                    Label lbl2 = (Label)Master.FindControl("Name");
                    Users u = Users.GetName(Session["Username"].ToString());
                    lbl2.Text = u.firstName + " " + u.lastName;
                    Label lbl3 = (Label)Master.FindControl("Country");
                    lbl3.Text = Session["country"].ToString();
                    Button btn3 = (Button)Master.FindControl("Button4");
                    if (User.IsInRole("admin"))
                    {
                        btn3.Visible = true;
                    }
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            EduForumReply efr = new EduForumReply();
            string name = Session["userName"].ToString();
            string reply = TextBox3.Text;
            string category = "Education";
            DateTime myDateTime = DateTime.Now;
            int EF_ID = Convert.ToInt32(Request.QueryString["id"]);
            //DateTime myDateTime2 = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
            //DateTime.Parse(DateTime.Now, ,"{0::MM/dd/yy HH:mm:ss tt}");
            string path = "";
            string iname = "";
            string country = "";
            List<Users> results = Users.GetUser();
            foreach (Users u in results)
            {
                if (Session["Username"].ToString() == u.userName.ToString())
                {
                    path = u.imagePath.ToString();
                    iname = u.imageName.ToString();
                    country = u.country.ToString();
                }
            }
            string title = "";
            List<EduForum> result = EduForum.GetEduForum();
            foreach (EduForum ef in result)
            {
                if(Request.QueryString["id"].ToString() == ef.EduForumID.ToString())
                {
                    title = ef.title.ToString();
                }
            }
            EduForumReply.insertEduReply(name, reply, EF_ID, myDateTime, category, iname, path, title, country);
            EduForum.updateEduReplyForum(EF_ID);
            EduForum.updateEduReplyForumDate(EF_ID, myDateTime);
            Annoucement.InsertAnnoucement("", "", "", myDateTime, "", name, reply, category, title.ToString(), "", 0, "", "");
            EduAnnouncement.InsertEduAnnoucement("", "", myDateTime, "", name, reply, title.ToString());
            Page.Response.Redirect(Page.Request.Url.ToString(), true);

        }



        
    }
}